package com.lianxian.xindong.old.fragment.home.dynamic.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;

import com.lianxian.xindong.old.R;
import com.lianxian.xindong.old.fragment.home.selffile.adapter.utils.GlideUtil;

import java.util.List;

public class GridAdapter extends BaseAdapter {
    private LayoutInflater layoutInflater;
    private List<String> data;
    private Context context;

    public GridAdapter(Context context,List<String> data) {
        this.context = context;
        layoutInflater = LayoutInflater.from(context);
        this.data = data;
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public Object getItem(int position) {
        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView==null){
            viewHolder = new ViewHolder();
            convertView = layoutInflater.inflate(R.layout.item_grid_image,parent,false);
            viewHolder.imageView = convertView.findViewById(R.id.grid_imageview);
            convertView.setTag(viewHolder);
        }else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        GlideUtil.GlideWithPlaceHolder(context, data.get(position)).into(viewHolder.imageView);

        return convertView;
    }
    private class ViewHolder{
        private ImageView imageView;

        public ViewHolder() {

        }

        public ImageView getImageView() {
            return imageView;
        }

        public void setImageView(ImageView imageView) {
            this.imageView = imageView;
        }

        public ViewHolder(ImageView imageView) {
            this.imageView = imageView;
        }
    }
}
